package exam.day26;

import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        int[] b = new int[n];
        int max = 0;
        for(int i = 0; i < n; i++) {
            if (i == 0 || i == 1) {
                b[i] = a[i];
            }
            int maxj = 0;
            for(int j = i - 2; j >= 0; j--) {
                maxj = Math.max(maxj, b[j]);
            }
            b[i] = maxj + a[i];
            max = Math.max(max, b[i]);
        }
        System.out.println(max);
    }
}
